package com.sjq.yqgl.web;

import java.util.Map;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.sjq.common.web.SessionUserHelper;
import net.sf.json.JSONObject;
import com.sjq.common.entity.Result;
import com.sjq.common.entity.LoginAccount;
import com.sjq.common.service.UserService;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import com.sjq.yqgl.service.YqmqjczService;
import com.sjq.yqgl.entity.Yqmqjcz;
import com.sjq.common.util.PageResults;

@Controller
public class YqmqjczController {
	@Autowired
    private YqmqjczService yqmqjczService;
    @Autowired
    private HttpSession session;  
    private static final String INITURL = "yqmqjcz/"; 
   /**查询列表***/
   @RequestMapping(INITURL+"YqmqjczList")
   @ResponseBody
   public JSONObject  YqmqjczList(Integer pageNo, Integer pageSize, Yqmqjcz yqmqjcz){
 	  if(yqmqjcz==null){
    		yqmqjcz=new Yqmqjcz();
    	} 	 
 	  SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        String role=la.getUserRole();
     	   if(role.equals("0001")){
     		   
     		   
     	   }else  if(role.equals("0002")){
     		   //分县局上报
     		  yqmqjcz.setDjrjh(la.getAccountId());
     		   
     	   }
   	   pageNo = pageNo == null ? 1 : pageNo;
       PageResults<?> pageResults=yqmqjczService.findYqmqjczByPage(pageNo, PageResults.ALLPAGESIZE, yqmqjcz);
       JSONObject json=new JSONObject();
       json.put("dataList", pageResults.getResults());
       json.put("pageNo",  pageResults.getPageNo());
       json.put("pages", pageResults.getPageCount());
       return json;
   }
   
    /**提交表单---不含文件**/
    @RequestMapping(INITURL+"addYqmqjcz")
	@ResponseBody
	 public JSONObject addYqmqjcz(Yqmqjcz yqmqjcz) {
	   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       LoginAccount la= helper.getLoginAccount();
       return yqmqjczService.addYqmqjcz(yqmqjcz, la);
    }
    
    /**提交表单---含附件**/
    @RequestMapping(INITURL+"addYqmqjczFiles")
	 public ModelAndView addYqmqjczFiles(Yqmqjcz yqmqjcz,@RequestParam("fj") CommonsMultipartFile[]  fj) {
	   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       LoginAccount la= helper.getLoginAccount();
       yqmqjczService.addYqmqjczFilesByFTP(yqmqjcz,fj, la);
       ModelAndView mav=new ModelAndView();
	   mav.setViewName("/view/common/ok");
	   return mav;
    }
    /**删除信息**/
     @RequestMapping(INITURL+"deleteYqmqjcz")
	 @ResponseBody
	 public JSONObject deleteYqmqjcz(String yqmqjczId) {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        return yqmqjczService.deleteYqmqjcz(yqmqjczId,la);
    }	
    
    
    /**更新表单**/
     @RequestMapping(INITURL+"motifyYqmqjcz")
	 @ResponseBody
	 public JSONObject motifyYqmqjcz(Yqmqjcz yqmqjcz) {
        SessionUserHelper helper = SessionUserHelper.createBySession(session);
        LoginAccount la= helper.getLoginAccount();
        return  yqmqjczService.updateYqmqjcz(yqmqjcz,la);   
    }	
    
    
     /**
    * @description 根据查询条件查询表的所有详细信息
    **/
	@RequestMapping(INITURL+"findYqmqjczAllList")
    @ResponseBody
    public JSONObject  findYqmqjczAllList(Yqmqjcz yqmqjcz){
 		   SessionUserHelper helper = SessionUserHelper.createBySession(session);
       	   LoginAccount la= helper.getLoginAccount();
		   return  yqmqjczService.findYqmqjczByListAll(yqmqjcz,la);  	
     }
   
   
}
